package vim.meet.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AdviceParameterAspect {
    
    @Pointcut("this(cn.freemethod.business.param.IAdviceParameter)")
    public void iAdviceParameter(){}
    
    @Before("iAdviceParameter() && args(arg,arg1,..)")
    public void joinPointParamterMethodBefore(String arg1,Integer arg){
        System.out.println("AdviceParameterAspect Advice Before:"+arg1);
        System.out.println("AdviceParameterAspect Advice Before:"+arg);
    }
    
//    @After("iAdviceParameter()")
    public void joinPointParamterMethodAfter(JoinPoint jp){
        System.out.println("AdviceParameterAspect Advice After...");
        Object[] args = jp.getArgs();
        for (int i = 0; i < args.length; i++) {
            System.out.println(args[i]);
        }
        System.out.println("kind:"+jp.getKind());
        System.out.println("target:"+jp.getTarget());
        System.out.println("proxy:"+jp.getThis());
        System.out.println("signature:"+jp.getSignature());
        System.out.println("AdviceParameterAspect Advice After...");
    }
    
//    @Around("iAdviceParameter()")
    public void joinPointParamterMethodAround(ProceedingJoinPoint pjp){
        System.out.println("AdviceParameterAspect Advice Around...");
        Object[] args = pjp.getArgs();
        for (int i = 0; i < args.length; i++) {
            System.out.println(args[i]);
        }
        System.out.println("AdviceParameterAspect Advice Around...");
    }
    
//    @Around("iAdviceParameter()")
    public Object joinPointParamterMethodAroundWithResult(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("AdviceParameterAspect Advice Around...");
        Object[] args = pjp.getArgs();
        for (int i = 0; i < args.length; i++) {
            System.out.println(args[i]);
        }
        System.out.println("AdviceParameterAspect Advice Around...");
        return pjp.proceed();
    }

}
